package exsun.jt808.data.media.operate.encode.codec;

import exsun.jt808.data.config.MediaEncoding;
import exsun.jt808.data.media.data.MediaConfig;
import exsun.jt808.data.media.operate.codec.G711Codec;

/**
 * pcm转aac
 */
public class PcmToAacCodec implements CodecBase {
    private EasyAacCodec easyAACCodec = new EasyAacCodec(MediaEncoding.Encoding.G711A);

    private G711Codec g711Codec = new G711Codec();

    @Override
    public void init(MediaConfig config, String clientChannelId) {
        easyAACCodec.init(config, clientChannelId);
    }

    @Override
    public byte[] decode(String clientChannelId, byte[] data) {
        //pcm->g711a
        byte[] g711a = g711Codec.fromPCM(data);
        //g711a->aac
        return easyAACCodec.decode(clientChannelId, g711a);
    }

    @Override
    public void release(String clientChannelId) {
        easyAACCodec.release(clientChannelId);
    }
}
